document.addEventListener('DOMContentLoaded', () => {
    //从sessionStorage中取出相关信息
    const items = JSON.parse(sessionStorage.getItem('selectedItems')) || [];
    const orderList = document.getElementById('orderList');
    const deliveryFee = 3;

    let total = 0;

    items.forEach(item => {
        const itemTotal = item.price * item.quantity;
        total += itemTotal;

        const div = document.createElement('div');
        div.className = 'item';
        div.innerHTML = `
          <div class="item-content">
            <img src="${item.imgSrc}" width="50" />
            <span>${item.name} × ${item.quantity}</span>
          </div>
          <span>¥${item.price}</span>
    `   ;
        orderList.appendChild(div);
    });

    total += deliveryFee;
    document.getElementById('total').innerText = total.toFixed(2);
});

function toPay(){
    window.location.href = 'payment.html';
}